#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define ll long long
#define fi first
#define se second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define getBit(mask, k) (((mask) / pw[k]) % pw[1])
#define setBit(mask, k, l) (((mask) / pw[k + 1] * pw[1] + (l)) * pw[k] + ((mask) % pw[k]))
#define debug(a) cerr << #a << " = " << (a) << " ";
#define debugl(a) cerr << #a << " = " << (a) << "\n";
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define ff first
#define ss second 
const ldb eps = 1e-9;
const int inf = 1 << 28;
const ldb pi = fabsl(atan2l(0.0, -1.0));
using namespace std;


int n, k;
int pos[2000011];

void load()
{
	cin >> n >> k;
	for (int i = 0; i < k; i++)
	{
		scanf("%d", &pos[i]);
	}
	sort(pos, pos + k);
}

inline int left(int p, int i)
{
	if (pos[p] < i) return i - pos[p];
	else return 2 * n - abs(pos[p] - i);
}

inline int right(int p, int i)
{
	if (pos[p] >= i) return pos[p] - i;
	else return 2 * n - abs(pos[p] - i);
}

void solve()
{
	for (int i = 1; i <= n; i++)
	{
		
	}
	int p = 0;
	ll cur = 0;
	for (int i = 0; i < k; i++)
	{
		cur += (ll)min(left(i, 1), right(i, 1));
	}
	int l = 0, r;
	for (int i = k - 1; i >= 0; i--)
	{
		if (left(i, 1) < right(i, 1))
			l++;
		else break;
	}
	
	r = k - l;
	//cerr << left(0, 1) << " " << right(0, 1) << "\n";
//	cerr << l << " " << r << "\n";
	ll res = 1ll << 60;
	/*
	for (int i = 0; i < k; i++)
	{
		cerr << pos[i] << " ";
	}
	cerr << "\n"; */
	for (int i = 1; i <= 2 * n; i++)
	{
	//	cerr << i << ": l = " << l << " r = " << r << " p = " << p << " cur = " << cur << "\n";
		while (l > 0 && left((p - l + k) % k, i) >= right((p - l + k) % k, i))
		{
			cur -= (ll)left((p - l + k) % k, i);
			cur += (ll)right((p - l + k) % k, i);
			l--;
			r++;
		}
	//	cerr << i << ": l = " << l << " r = " << r << " p = " << p << " cur = " << cur << "\n";
		if (pos[p] == i)
		{
			l++;
			r--;
			p++;
			cur += (ll)l;
			cur -= (ll)r;
			continue;
		}	
		if (cur < res) res = cur;
		cur += (ll)l;
		cur -= (ll)r;
	}
	cout << res;
}

#define file "circle"
int main()
{
	freopen(file".in", "rt", stdin);
	freopen(file".out", "wt", stdout);
	load();
	solve();
	return 0;
}
